package com.emily.test.service.impl;

import com.emily.test.mapper.TCompanyInfoMapper;
import com.emily.test.mapper.TUserMapper;
import com.emily.test.model.TCompanyInfo;
import com.emily.test.model.TUser;
import com.emily.test.service.TUserService;
import com.emily.test.utils.ConstentUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("tUserServiceAgent")
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,timeout=36000,rollbackFor=Exception.class)
public class TUserServiceImpl implements TUserService {

    @Resource
    private TUserMapper tUserMapper;
    @Resource
    private TCompanyInfoMapper tCompanyInfoMapper;

    @Override
    public List<TUser> getUserInfoListByCondition(TUser tUser) {
        return tUserMapper.getUserInfoListByCondition(tUser);
    }

    @Override
    public List<TUser> selectIsExistByCondition(TUser tUser) {
        return tUserMapper.selectIsExistByCondition(tUser);
    }

    @Override
    public int insertUser(TUser tUser) {
        return tUserMapper.insertSelective(tUser);
    }

    @Override
    public TUser getUserInfoById(Integer id) {
        return tUserMapper.getUserInfoById(id);
    }

    @Override
    public int updateUserInfoByUserId(TUser tUser) {
        return tUserMapper.updateUserInfoByUserId(tUser);
    }

    @Override
    public List<TUser> getUserListWithOutCompany(TUser tUser) {
        return tUserMapper.getUserListWithOutCompany(tUser);
    }

    @Override
    public int removeUserFromCompanyByUserIds(List<Integer> userIdList) {
        return tUserMapper.removeUserFromCompanyByUserIds(userIdList);
    }

    @Override
    public int updateUserByIds(List<TUser> tUserList) {
        return tUserMapper.updateUserByIds(tUserList);
    }

    @Override
    public int findNumByPhoneWithOutId(TUser ts) {
        return tUserMapper.findNumByPhoneWithOutId(ts);
    }

    @Override
    public TUser findUsertByCode(String code) {
        TCompanyInfo tCompanyInfo = tCompanyInfoMapper.selectInfoByCode(code);
        return tUserMapper.findUsertByCode(tCompanyInfo.getEmail());
    }

    @Override
    public List<TUser> getUserListNoRoles() {
        return tUserMapper.getUserListNoRoles();
    }
}
